package com.compass;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
public class SpringUtils implements ApplicationContextAware{
    private static ApplicationContext ctx;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if(ctx == null){
            this.ctx = applicationContext;
        }
    }

    public static Object getBean(String beanName){
        return ctx.getBean(beanName);
    }

    public static Object getBean(Class cls){
        return ctx.getBean(cls);
    }
}
